<template>
  <div class="cart-item">
    <div class="item-select">
      <div class="check-one" :class="{ active: cartItem.checked }" @click="checkOne"></div>
    </div>

    <div class="item-img">
      <img :src="cartItem.image" @load="cartImgLoad" />
    </div>

    <div class="item-info">
      <h3 class="item-title">{{ cartItem.title }}</h3>
      <div class="item-desc">{{ cartItem.description }}</div>
      <div class="info-bottom">
        <div class="item-price">￥{{ cartItem.price }}</div>
        <div class="item-count">{{ cartItem.count }}</div>
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    name: 'cart-item',
    props: {
      cartItem: {
        type: Object,
        default() {
          return {}
        }
      }
    },
    methods: {
      cartImgLoad() {
        this.$bus.$emit('cartImgLoad')
      },
      checkOne() {
        this.$store.commit('checkOne', this.cartItem)
      }
    }
  }
</script>

<style lang="less" scoped>
  .cart-item {
    display: flex;
    align-items: center;
    padding: 5px 10px 5px 5px;
    border-bottom: 1px solid #ccc;
  }
  .item-img {
    margin: 0 8px;
  }
  .item-img img {
    width: 70px;
    border-radius: 5px;
    vertical-align: middle;
  }
  .item-info {
    position: relative;
    height: 100px;
    overflow: hidden;
  }
  .item-title,
  .item-desc {
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
  }
  .item-title {
    margin-bottom: 5px;
    font-size: 14px;
  }
  .item-desc {
    font-size: 12px;
  }
  .item-price {
    color: var(--color-tint);
  }
  .info-bottom {
    display: flex;
    justify-content: space-between;
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
  }
  .check-one {
    width: 16px;
    height: 16px;
    border: 3px solid #ccc;
    border-radius: 8px;
  }
  .active {
    background-color: red;
  }
</style>
